using System;
using System.Collections.Generic;
//using AvantGameMachine.GameMachineClient;

namespace AvantGameMachine
{
	namespace DataManagement
	{
		public class Address : Object
		{
			private List<string> values = null;
/*			
			public static Address GetFileAddress(string _file) {
				return new Address(ClientManager.GetInstance().GetActiveClientDirectory() + "/" + _file);
			}
			
			public static Address GetFileAddress(Address _address) {
				return new Address(ClientManager.GetInstance().GetActiveClientDirectory() + "/" + _address.ToString());
			}			
            */
			public Address()
			{
				values = new List<string>();
			}
			
			public Address(string _address) {
				values = new List<string>();
				
				string[] data = _address.Split(new string[] {"/"},StringSplitOptions.RemoveEmptyEntries);
				foreach (string dt in data) {
					values.Add(dt);
				}
			}
			
			public Address(List<string> _values) {
				this.values = _values;
			}
			
			public string[] GetArray() {
				return values.ToArray();
			}
			
			public override string ToString ()
			{
				string result = "";
				foreach (string val in values) {
					if (result != "")
						result += "/";
					result += val;
				}
				return result;
			}
			
			public int GetLen() {
				return values.Count;
			}
			
			public Address GetRange(int _start,int _len) {
				if (_len == 0)
					return new Address();
				
				if (_len < 0)
					_len =values.Count - _start;

				Address cp = new Address(values.GetRange(_start,_len));
				return cp;
			}

			public string GetValueAt(int _index) {
				if (_index < values.Count) {
					return values[_index];
				}
				
				return null;
			}

			public Address clone()
			{
				Address other = new Address(this.ToString());
				return other;
			}

			public Address AddPrefix(Address _newData) {
				Address copy = _newData.clone();
				
				foreach (string data in values) {
					copy.values.Add(data);
				}
				
				return copy;
			}

			public Address AddSufix(Address _newData) {
				Address copy = this.clone();
				
				foreach (string data in _newData.values) {
					copy.values.Add(data);
				}
				
				return copy;
			}
			
			public Address RemovePrefix() {
				Address copy = this.clone();
				
				if (copy.values.Count > 0)
					copy.values.RemoveAt(0);
				
				return copy;
			}

			public Address RemoveSufix() {
				Address copy = this.clone();
				
				if (copy.values.Count > 0)
					copy.values.RemoveAt(copy.values.Count - 1);
				
				return copy;
			}
		}
	}
}

